home *** CD-ROM | disk | FTP | other *** search
- Path: bcrkh13.bnr.ca!news
- From: coopeng <coopeng@bnr.ca>
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: Converting integer to char/string?
- Date: 5 Feb 1996 19:59:38 GMT
- Organization: NORTEL
- Message-ID: <4f5nja$jrg@bcrkh13.bnr.ca>
- References: <4f5ehf$48i@brtph500.bnr.ca>
- NNTP-Posting-Host: bkani3f.bnr.ca
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
-
- borland : char *itoa(int num, const char *str,int radix);
-
- itoa is not currently defined by the ANSI C standard.
-
- itoa() function converts the integer "num" into its string equivalent and places the
- result in the string pointed to by str. The base of the output string is determined
- by radix, (range 2 - 16).
-
- If your compiler doesn't have itoa, this function may help you
-
- base 10
- -------
-
- itoa(in_num,out_char)
- int in_num;
- char *out_char;
- {
- int i, count, len;
- char temp[10];
-
- for ( count=0; in_num>0; count++)
- {
- i=(in_number %10);
- *(temp+count)=i+'0';
- in_num /=10;
- }
- *(temp+count) ='\0';
- len=strlen(temp);
- for(count=0; count<len;count++)
- *(out_char +len-count-1)=*(temp+count);
- *(out_char+len)='\0';
- }
-
- /* This code can be found in "The C Trilogy by Eric P.Bloom" */
-
- I didn't compile this function, but this will give you an idea I hope.
-
-
-